home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #11
/
Amiga Plus CD - 2004 - No. 11.iso
/
AmiSoft
/
Misc
/
emu
/
fbzx.lha
/
fbzx
/
sound_ahi.c
< prev
next >
Wrap
C/C++ Source or Header
|
2004-08-26
|
2KB
|
110 lines
#include "Z80.h"
#include "computer.h"
#include "emulator.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <devices/ahi.h>
#include <proto/alib.h>
#include <proto/exec.h>
char sound_type; // 0=OSS, 1=no sound
static struct AHIRequest *io = NULL;;
static struct MsgPort *port = NULL;
static int pending = 0;
static UWORD sample_buf[4096];
int sound_init(int wfreq,int wbuff) {
struct AHIRequest *req;
int bytes,stereo;
if(sound_type==1) { // no sound; simulate 8bits mono
ordenador.sign=0;
ordenador.format=0;
ordenador.channels=1;
ordenador.channels = 1;
ordenador.freq=48000;
ordenador.buffer_len=4800; // will wait 1/10 second
return (0);
}
port = CreateMsgPort();
req = (struct AHIRequest *)CreateIORequest(port, sizeof(*req));
if (req)
{
req->ahir_Version = 4;
if (OpenDevice("ahi.device", 0, (struct IORequest *)req, 0) == 0)
{
req->ahir_Std.io_Command = CMD_WRITE;
io->ahir_Std.io_Data = sample_buf;
req->ahir_Std.io_Offset = 0;
req->ahir_Std.io_Length = 4096*2;
req->ahir_Type = AHIST_M16S;
req->ahir_Frequency = 48000;
req->ahir_Volume = 0x10000;
req->ahir_Position = 0x8000;
req->ahir_Link = NULL;
io = req;
bytes=0; //8 bits
stereo=0; // no stereo
ordenador.sign=-128;
ordenador.format=2;
ordenador.channels = 1;
ordenador.freq=48000;
ordenador.buffer_len=4096;
return 0;
}
DeleteIORequest((struct IORequest *)req);
}
DeleteMsgPort(port);
return -1;
}
void sound_play() {
ordenador.current_buffer=sound[0];
if(sound_type==1) { // no sound
TimeDelay(0, 0, 75000); // wait 1/20 second
return;
}
if (pending)
WaitIO((struct IORequest *)io);
CopyMemQuick(sound[0], sample_buf, 4096*2);
SendIO((struct IORequest *)io);
pending = 1;
}
void sound_close() {
if(sound_type==0)
{
if (io)
{
if (pending)
{
AbortIO((struct IORequest *)io);
WaitIO((struct IORequest *)io);
}
CloseDevice((struct IORequest *)io);
DeleteIORequest((struct IORequest *)io);
DeleteMsgPort(port);
}
}
}